const mysql = require('mysql2/promise')
const dotenv = require("dotenv");
dotenv.config({ path: `.env.${process.env.NODE_ENV}` })
const db = mysql.createPool({
    host: process.env.MYSQL_DATACENTER_HOST,
    port: process.env.MYSQL_DATACENTER_PORT,
    user: process.env.MYSQL_DATACENTER_USER,
    password: process.env.MYSQL_DATACENTER_PASSWORD,
    database: process.env.MYSQL_DATACENTER_DATABASE,
    connectionLimit: 10
})
// 测试数据库是否连接成功
db.getConnection((err, conn) => {
  conn.connect(err => {
    if (err) {
      console.log('连接失败~')
    } else {
      console.log('连接成功~')
    }
  })
})

module.exports = db
